<template>
  <view class="user px-[24rpx] py-0">
    <custom-navbar :title="title" />
    <up-gap height="30rpx" />
    <view class="user-content">
      <view
        class="relative z-10 w-[100%] rounded-[44rpx] bg-#fdfeff p-[24rpx] shadow-[0rpx_6rpx_12rpx_0rpx_rgba(235,235,235,0.30)]"
      >
        <view class="flex justify-between">
          <view class="relative flex" @click="toUserInfo">
            <image
              :src="userInfo.avatar"
              class="block h-[124rpx] w-[124rpx] rounded-[50%] shrink-0"
            >
            </image>
            <view class="pl-[26rpx] h-[124rpx] flex flex-col justify-center">
              <view
                class="h-14 text-left text-[40rpx] text-[#333333] font-medium"
              >
                {{ userInfo.name }}
              </view>
              <view
                class="tracking-[1.56rpx]; h-9 text-left text-[26rpx] text-[#999999] font-medium leading-[44rpx]"
              >
                {{ userInfo.school?userInfo.school.name:'' }}
              </view>
            </view>
            <image
              src="https://yiliao.test03.qcw800.com/static/images/tab/user-01.png"
              class="top-[96rpx]; absolute left-[96rpx] h-[28rpx] w-[28rpx]"
            >
              <view class="h-[124rpx] flex flex-col justify-center">
                <view
                  class="h-14 text-left text-[40rpx] text-[#333333] font-medium"
                >
                  牛大胆
                </view>
                <view
                  class="tracking-[1.56rpx]; h-9 text-left text-[26rpx] text-[#999999] font-medium leading-[44rpx]"
                >
                  北京科技大学
                </view>
              </view>
              <image
                src="https://yiliao.test03.qcw800.com/static/images/tab/user-01.png"
                class="top-[96rpx]; absolute left-[96rpx] h-[28rpx] w-[28rpx]"
              />
            </image>
          </view>
          <view
            class="PingFang HK, PingFang HK-Regular leading-[30rpx]; font-family: h-[56rpx] w-[192rpx] flex items-center justify-center rounded-[28rpx] bg-#f5f6fa text-left text-[24rpx] text-[#4e5969] font-normal"
            @click="setStatus"
          >
            {{ currStatus }}
            <view class="iconfont icon-xiajiantou" />
          </view>
        </view>
        <view v-if="clientType == 'customer'" class="mt-[30rpx] flex">
          <view
            v-for="(item, index) in list"
            :key="index"
            class="flex flex-1 flex-col items-center"
            @click="to(item)"
          >
            <view class="text-left text-[34rpx] text-[#1d2129] font-bold">
              {{ mineInfo[item.key] }}
            </view>
            <view class="text-[#4e5969]; text-left text-[20rpx] font-medium">
              {{ item.text }}
            </view>
          </view>
        </view>
      </view>
      <view
        class="relative z-9 mt-[-62rpx] h-[190rpx] w-[100%] rounded-[0_0_44rpx_44rpx] bg-#fee7c7 px-[24rpx] pb-[24rpx] pr-[24rpx] pt-[82rpx]"
      >
        <view
          class="text-left text-left text-[30rpx] text-[#aa640a] font-medium font-medium leading-[50rpx] tracking-[1.8rpx]"
        >
          医疗垂直-全新体验
        </view>
        <view class="flex items-center">
          <view
            style="background: rgb(170 100 10 / 10%)"
            class="mr-[16rpx] flex items-center justify-center rounded bg-#aa640a p-[4rpx] text-[14rpx] text-[#AA640A]"
          >
            广告
          </view>
          <view class="text-[#AA640A]"> 文案内容,内容内容 </view>
        </view>
      </view>
    </view>
    <up-gap height="30rpx" />
    <Menu :menu-list="menuList" />
    <up-gap height="30rpx" />
    <Menu :menu-list="menuListOther" />
    <up-gap height="30rpx" />
    <MySwiper :swiper-img="bannerList" swiper-height="260rpx" />
    <up-gap height="200rpx" />

    <up-picker
      :show="show"
      :columns="columns"
      @confirm="confirm"
      @cancel="show = false"
    />
  </view>
</template>

<script setup lang="ts">
import Menu from "@/pages/components/menu/index.vue";
import MySwiper from "@/pages/components/myswiper/index.vue";

// import user03 from "@/static/images/tab/user-03.png";
// import user04 from "@/static/images/tab/user-04.png";
// import user05 from "@/static/images/tab/user-05.png";
// import user13 from "@/static/images/tab/user-13.png";
// import user10 from "@/static/images/tab/user-10.png";

// import user09 from "@/static/images/tab/user-09.png";
// import user06 from "@/static/images/tab/user-06.png";
// import user07 from "@/static/images/tab/user-07.png";
// import user08 from "@/static/images/tab/user-08.png";

// import user14 from "@/static/images/tab/user-14.png";
import { mineUserInfo, updateUserInfo, userUserInfo, userBanner } from "@/api/user";
import { useUserStore } from "@/store";
const user03 = "https://yiliao.test03.qcw800.com/static/images/tab/user-03.png";
const user04 = "https://yiliao.test03.qcw800.com/static/images/tab/user-04.png";
const user05 = "https://yiliao.test03.qcw800.com/static/images/tab/user-05.png";
const user13 = "https://yiliao.test03.qcw800.com/static/images/tab/user-13.png";
const user10 = "https://yiliao.test03.qcw800.com/static/images/tab/user-10.png";

const user09 = "https://yiliao.test03.qcw800.com/static/images/tab/user-09.png";
const user06 = "https://yiliao.test03.qcw800.com/static/images/tab/user-06.png";
const user07 = "https://yiliao.test03.qcw800.com/static/images/tab/user-07.png";
const user08 = "https://yiliao.test03.qcw800.com/static/images/tab/user-08.png";

const user14 = "https://yiliao.test03.qcw800.com/static/images/tab/user-14.png";
const title = ref("个人中心");
interface ListItem {
  text: string;
  num: string;
  key: string;
  filed: string;
  url?: string;
}
const list = reactive<ListItem[]>([
  {
    text: "我看过",
    num: "99+",
    key: "me_look_count",
    filed: "filed1",
    url: "/pages/userinfo/viewed",
  },
  {
    text: "沟通过",
    num: "99+",
    key: "talk_count",
    filed: "filed2",
    // url:'/pages/userinfo/scanbyme'
  },
  {
    text: "已投递",
    num: "99+",
    key: "resume_send_count",
    filed: "filed3",
    url: '/pages/common/delivery-progress/index'
  },
  {
    text: "看过我",
    num: "99+",
    key: "look_me_count",
    filed: "filed3",
    url: "/pages/userinfo/scanbyme",
  },
]);
const to = (params: any) => {
  let url = params.url;
  console.log('公司key:::', params.key,'公司ID：：：', companyId.value)
  switch (params.key) {
    case "me_look_count":
      url = url + "?status=1";
      break;
    case "talk_count":
      url = url + "?status=2";
      break;
    case "resume_send_count":
      url = url + "?status=3";
      break;
    case "look_me_count":
      url = url + "?status=4";
      break;
    case "company":
      url = url + "?company_id";
      break;
  }
  // uni.navigateTo({
  //   url: url,
  // });
};
// 定义接口
interface MenuItem {
  ico: string;
  key: string;
  text: string;
  url?: string;
}
const companyId = ref(0);
let menuList = ref(null);
let menuListOther = ref(null);
// 使用 `MenuItem` 接口定义 `reactive` 数据
const menuListUser = reactive<MenuItem[]>([
  {
    ico: user03,
    key: '',
    text: "我的简历",
    url: "/pages/userinfo/resume",
  },
  {
    ico: user04,
    key: '',
    text: "求职偏好",
    url: "/pages/tab/home/more/preference"
  },
  {
    ico: user05,
    key: '',
    text: "教育经历",
    url: "/pages/tab/home/more/educationExperience"
  },
  {
    ico: user13,
    key: '',
    text: "我的内推",
    url: "/pages/userinfo/referral",
  },
  {
    ico: user10,
    key: '',
    text: "关注公众号",
  },
]);
const menuListOtherUser = reactive<MenuItem[]>([
  {
    ico: user09,
    key: '',
    text: "身份认证",
    url: "/pages/userinfo/auth",
  },
  {
    ico: user06,
    key: '',
    text: "投诉企业",
    url: "/pages/userinfo/feedback",
  },
  {
    ico: user07,
    key: '',
    text: "意见反馈",
    url: "/pages/userinfo/suggestions",
  },
  {
    ico: user08,
    key: '',
    text: "设置中心",
    url: "/pages/userinfo/settings",
  },
]);

const menuListEnterprise = reactive<MenuItem[]>([
  {
    ico: user03,
    key: '',
    text: "简历管理",
    url: "/pages/enterprise/enterprise-info/resumeManagement",
  },
  {
    ico: user04,
    key: '',
    text: "职位管理",
    url: "/pages/common/recp-positions/index?type=1",
  },
  {
    ico: user05,
    key: '',
    text: "招聘偏好",
    url: "/pages/enterprise/enterprise-info/recPreferences",
  },
  {
    ico: user13,
    key: '',
    text: "老师内推",
    url: "/pages/enterprise/enterprise-info/teacherRecom",
  },
  {
    ico: user10,
    key: '',
    text: "关注公众号",
  },
]);

const menuListOtherEnterprise = reactive<MenuItem[]>([
  {
    ico: user06,
    key: 'company',
    text: "公司主页",
    url: "/pages/common/company/index"
  },
  {
    ico: user06,
    key: '',
    text: "广告合作",
    url: "/pages/enterprise/enterprise-info/advManagement",
  },
  {
    ico: user09,
    key: '',
    text: "身份认证",
    url: "/pages/userinfo/auth",
  },

  {
    ico: user07,
    key: '',
    text: "意见反馈",
    url: "/pages/userinfo/suggestions",
  },
  {
    ico: user08,
    key: '',
    text: "设置中心",
    url: "/pages/userinfo/settings",
  },
]);
const swiperImg = reactive([user14, user14, user14]);

const currStatus = ref("");
const show = ref(false);
const columns = reactive([["正在看机会", "已找到工作", "离职状态"]]);

const setStatus = () => {
  show.value = true;
};
const confirm = (v) => {
  currStatus.value = v.value[0];
  console.log(v.value[0]);
  show.value = false;
  updateUserStatus({
    job_status:
      v.value[0] === "正在看机会" ? 1 : v.value[0] === "已找到工作" ? 2 : 3,
  });
};
const toUserInfo = () => {
  uni.navigateTo({
    url: "/pages/userinfo/index",
  });
};
const userInfo = ref({
  name: "",
  school: {
    name: "",
  },
  job_status: 1, //1正在看机会  2已找到工作  3离职状态
});

const getUserInfo = async () => {
  try {
    const result = await userUserInfo();
    console.log("我的-用户详情", result);
    userInfo.value = result;
    type ClientType = "customer" | "enterprise";
    const { clientType } = useUserStore();
    if (clientType == "enterprise") {
      companyId.value = result.hr.company_id;
      console.log('我的详情-公司ID:::', companyId.value)
      menuListOtherEnterprise[0] = {
        ico: user06,
        key: 'company',
        text: "公司主页",
        url: "/pages/common/company/index?company_id=" + companyId.value
      }
      console.log('公司id--------：：：',menuListOtherEnterprise[0].url, companyId.value)
    }
  } catch (e) {
    console.log(e);
  }
};
const mineInfo = ref({
  me_look_count: 0,
  talk_count: 0,
  resume_send_count: 0,
  look_me_count: 0,
  like_count: 0,
});
const getMineInfo = async () => {
  try {
    const result = <any>await mineUserInfo();
    console.log("mine info:::", result);
    mineInfo.value = result;
  } catch (e) {
    console.log(e);
  }
};

const updateUserStatus = async (data: any) => {
  try {
    const result = <any>await updateUserInfo(data);
    console.log("result", result);
  } catch (e) {
    console.log(e);
  }
};
const bannerList:any = reactive([]);
async function getBanner(type:number) { //1首页
  let result = await userBanner({
    type: type
  });
  console.log('banner结果:::', result)
  for (let i = 0; i < result.length; i++) {
    const r = result[i]
    bannerList.push(r.image)
  }
}
onLoad(() => {
  getUserInfo();
  getMineInfo();
  getBanner(1);
  currStatus.value =
    userInfo.value.job_status === 1
      ? "正在看机会"
      : userInfo.value.job_status === 2
      ? "已找到工作"
      : "离职状态";
});
onShow(() => {
  getApp().globalData!.initTabbar(uni.$u.pages(), 3);
});

type ClientType = "customer" | "enterprise";
const clientType = uni.getStorageSync('clientType');;
menuList.value = clientType == "customer" ? menuListUser : menuListEnterprise;
console.log(companyId.value, '-------------')
menuListOther.value = clientType == "customer" ? menuListOtherUser : menuListOtherEnterprise;
</script>
